package org.lds.scheduled.job.admin.business.worker.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lds.scheduled.job.admin.business.worker.model.request.*;
import org.lds.scheduled.job.admin.business.worker.model.response.*;
import org.lds.scheduled.job.admin.business.worker.service.WorkerBaseService;
import org.lds.scheduled.job.common.model.dto.ResultDTO;
import org.lds.scheduled.job.common.model.db.OrderBy;
import org.lds.scheduled.job.common.model.db.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/worker")
public class WorkerBaseController {
    private final WorkerBaseService workerBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<WorkerBaseResponse> createWorker(@RequestBody @Validated WorkerBaseCreateRequest request) {
        return workerBaseService.createWorker(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<WorkerBaseBatchCreateResponse> batchCreateWorker(@RequestBody @Validated WorkerBaseBatchCreateRequest request) {
        return workerBaseService.batchCreateWorker(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<WorkerBaseDeleteResponse> deleteWorker(@RequestBody WorkerBaseDeleteRequest request) {
        return workerBaseService.deleteWorker(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<WorkerBaseBatchDeleteResponse> batchDeleteWorker(@RequestBody @Validated WorkerBaseBatchDeleteRequest request) {
        return workerBaseService.batchDeleteWorker(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<WorkerBaseResponse> updateWorker(@RequestBody @Validated WorkerBaseUpdateRequest request) {
        return workerBaseService.updateWorker(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<WorkerBaseBatchUpdateResponse> batchUpdateWorker(@RequestBody @Validated WorkerBaseBatchUpdateRequest request) {
        return workerBaseService.batchUpdateWorker(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<WorkerBaseListResponse> listWorker(@RequestBody WorkerBaseListRequest request) {
        return workerBaseService.listWorker(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<WorkerBaseListResponse> listAllWorker(@RequestBody OrderBy orderBy) {
        return workerBaseService.listAllWorker(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<WorkerBaseResponse> getWorkerById(@RequestBody @Validated WorkerBaseGetByIdRequest request) {
        return workerBaseService.getWorkerById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<WorkerBaseListResponse> getWorkerByIds(@RequestBody @Validated WorkerBaseGetByIdsRequest request) {
        return workerBaseService.getWorkerByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<WorkerBaseResponse>> listWorkerPage(@RequestBody WorkerBaseListPageRequest request) {
        return workerBaseService.listWorkerPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated WorkerBaseGetByKeyRequest request) {
        return ResultDTO.success(workerBaseService.getWorkerByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<WorkerBaseBatchCreateResponse> batchCreateWorkerAsync(@RequestBody @Validated WorkerBaseBatchCreateRequest request) {
        return workerBaseService.batchCreateWorkerAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<WorkerBaseBatchDeleteResponse> batchDeleteWorkerAsync(@RequestBody @Validated WorkerBaseBatchDeleteRequest request) {
        return workerBaseService.batchDeleteWorkerAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<WorkerBaseBatchUpdateResponse> batchUpdateWorkerAsync(@RequestBody @Validated WorkerBaseBatchUpdateRequest request) {
        return workerBaseService.batchUpdateWorkerAsync(request);
    }

}